﻿using AutoMapper;
using MediatR;
using RBAC.Api.Demain.ContentManagement;
using RBAC.Api.Erroc;
using RBAC.Api.Infaction;
using RBAC.Api.Writh.Command.ContentManagement;

namespace RBAC.Api.Writh.CommandHandler.ContentManagement
{
    public class AddCarouselChartCommandHandler : IRequestHandler<AddCarouselChartCommand, APIResult<object>>
    {
        private readonly IBaseRepositry<CarouselChartModel> baseRepositry;
        private readonly IMapper mapper;

        public AddCarouselChartCommandHandler(IBaseRepositry<CarouselChartModel> baseRepositry,IMapper mapper)
        {
            this.baseRepositry = baseRepositry;
            this.mapper = mapper;
        }
        public async Task<APIResult<object>> Handle(AddCarouselChartCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            result.Code = ResultCode.Success;
            result.Message = "添加轮播图表成功";

            var model = mapper.Map<CarouselChartModel>(request);

            await baseRepositry.Add(model);

            return await Task.FromResult(result);
        }
    }
}
